package com.ruoyi.web.controller.project;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.entity.PhaseDictionary;
import com.ruoyi.project.domain.query.PhaseDictionaryQuery;
import com.ruoyi.project.service.IPhaseDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/project/PhaseDictionary")
@Api(tags = "阶段流程配置", description = "")
public class PhaseDictionaryController {

    @Resource
    private IPhaseDictionaryService iPhaseDictionaryService;

    @ApiOperation("分页")
    @GetMapping(value = "/page")
    public R<TableDataInfo> page(PhaseDictionaryQuery query) {
        return R.ok(iPhaseDictionaryService.getDictionaryPage(query));
    }


    @ApiOperation("所有列表")
    @GetMapping(value = "/list")
    public R getList(PhaseDictionaryQuery query) {
        return R.ok(iPhaseDictionaryService.list());
    }



    @ApiOperation("新增")
    @PostMapping(value = "/save")
    public R savePhaseDictionary(@RequestBody PhaseDictionary dictionary) {
        return R.ok(iPhaseDictionaryService.saveDictionary(dictionary));
    }


    @ApiOperation("修改")
    @PutMapping (value = "/update")
    public R updatePhaseDictionary(@RequestBody PhaseDictionary PhaseDictionary) {
        return R.ok(iPhaseDictionaryService.updateDictionary(PhaseDictionary));
    }


    @ApiOperation("删除")
    @DeleteMapping (value = "/{menuId}")
    public R deletePhaseDictionary(  @PathVariable("menuId") Integer id) {
        return R.ok(iPhaseDictionaryService.deleteDictionarys(id));
    }



    @ApiOperation("详情")
    @GetMapping(value = "/details")
    public R<PhaseDictionary> getDetails(@RequestParam Integer id) {
        PhaseDictionary phaseDictionary = iPhaseDictionaryService.getById(id);
        return R.ok(phaseDictionary);
    }

    @ApiOperation("规则检查")
    @GetMapping(value = "/check")
    public R getCheck(PhaseDictionaryQuery query) {
        return R.ok(iPhaseDictionaryService.checkRule(query));
    }

    @ApiOperation("规则检查")
    @GetMapping(value = "/checkCosting")
    public void getCheckAmount(PhaseDictionaryQuery query) {
        iPhaseDictionaryService.checkCosting(query.getProjectNo());
    }

    @ApiOperation("检查下一步按钮的开放与隐藏")
    @GetMapping(value = "/next")
    public R getNext(PhaseDictionaryQuery query) {
        return R.ok(iPhaseDictionaryService.getNextPermission(query));
    }

}
